package com.hippo.core.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.hippo.core.R
import com.hippo.core.ui.theme.HippoTheme

@Composable
fun OptionButton(
    modifier: Modifier = Modifier,
    text:String? = null,
    checked:Boolean = false,
    normalImage: Painter,
    checkedImage: Painter,
    iconSize : Dp = 84.dp,
    onClick: (() -> Unit)? = null
) {

    val textColor = if (checked) MaterialTheme.colorScheme.primary else Color.Gray

    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = modifier
    ) {
        IconButton(onClick = {onClick?.invoke()},
            modifier = Modifier
                .size(iconSize)
                .background(
                    color = Color.Transparent,
                    shape = MaterialTheme.shapes.medium
                )
        ) {
           Image(
               painter = if (checked) checkedImage else normalImage,
               contentDescription = null,
           )
        }

        text?.let {
            Text(
                text = text,
                color = textColor
            )
        }
    }

}

@Preview
@Composable
private fun OptionButtonPreview() {
    HippoTheme {
        OptionButton(
            checked = false,
            normalImage = painterResource(R.mipmap.manual_n),
            checkedImage = painterResource(R.mipmap.manual_s),
            onClick = {}
        )
    }
}